1
|
|
|
/** |
2
|
|
|
* Add a listener to the Color Scheme control to update other color controls to new values/defaults. |
3
|
|
|
* Also trigger an update of the Color Scheme CSS when a color is changed. |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
( function( api ) { |
7
|
|
|
var cssTemplate = wp.template( 'lsx-color-scheme' ), |
|
|
|
|
8
|
|
|
skipUpdateCss = false; |
9
|
|
|
|
10
|
|
|
api.controlConstructor.select = api.Control.extend( { |
11
|
|
|
ready: function() { |
12
|
|
|
if ( 'color_scheme' === this.id ) { |
13
|
|
|
this.setting.bind( 'change', function( _value ) { |
14
|
|
|
skipUpdateCss = true; |
15
|
|
|
|
16
|
|
|
var _colors = colorScheme[_value].colors; |
|
|
|
|
17
|
|
|
|
18
|
|
|
_.each( _colors, function( _color, _setting ) { |
|
|
|
|
19
|
|
|
if ('function' === typeof api( _setting )) { |
20
|
|
|
api( _setting ).set( _color ); |
21
|
|
|
api.control( _setting ).container.find( '.color-picker-hex' ) |
22
|
|
|
.data( 'data-default-color', _color ) |
23
|
|
|
.wpColorPicker( 'defaultColor', _color ); |
24
|
|
|
} |
25
|
|
|
} ); |
26
|
|
|
|
27
|
|
|
skipUpdateCss = false; |
28
|
|
|
updateCSS(); |
29
|
|
|
} ); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
} ); |
33
|
|
|
|
34
|
|
|
// Generate the CSS for the current Color Scheme. |
35
|
|
|
function updateCSS() { |
36
|
|
|
if (skipUpdateCss) { |
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
var __scheme = api( 'color_scheme' )(), |
41
|
|
|
__css, |
42
|
|
|
__colors = colorScheme[ __scheme ].colors; |
|
|
|
|
43
|
|
|
|
44
|
|
|
// Merge in color scheme overrides. |
45
|
|
|
_.each( colorSchemeKeys, function( __setting ) { |
|
|
|
|
46
|
|
|
if ('function' === typeof api( __setting )) { |
47
|
|
|
__colors[ __setting ] = api( __setting )(); |
48
|
|
|
} |
49
|
|
|
} ); |
50
|
|
|
|
51
|
|
|
__css = cssTemplate( __colors ); |
52
|
|
|
api.previewer.send( 'update-color-scheme-css', __css ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// Update the CSS whenever a color setting is changed. |
56
|
|
|
_.each( colorSchemeKeys, function( __setting ) { |
|
|
|
|
57
|
|
|
api( __setting, function( __setting ) { |
58
|
|
|
__setting.bind( updateCSS ); |
59
|
|
|
} ); |
60
|
|
|
} ); |
61
|
|
|
} )( wp.customize ); |
|
|
|
|
62
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.